package com.amethyst.swagger3.demo.common.exception;

import com.amethyst.swagger3.demo.enums.CodeEnum;
import lombok.Getter;
import lombok.Setter;

/**
 * @author Amethyst
 * @date 2021/10/14
 */
@Getter
@Setter
public class BizException extends RuntimeException{
    private static final long serialVersionUID = 1L;
    /**
     * 错误码
     */
    protected Integer errorCode;
    /**
     * 错误信息
     */
    protected String errorMsg;

    public BizException() {
        super();
    }

    public BizException(CodeEnum codeEnum) {
        super(codeEnum.getMessage());
        this.errorCode = codeEnum.getCode();
        this.errorMsg = codeEnum.getMessage();
    }

    public BizException(CodeEnum codeEnum, Throwable cause) {
        super(codeEnum.getMessage(), cause);
        this.errorCode = codeEnum.getCode();
        this.errorMsg = codeEnum.getMessage();
    }

    public BizException(CodeEnum codeEnum, String errorMsg) {
        super(errorMsg);
        this.errorCode = codeEnum.getCode();
        this.errorMsg = errorMsg;
    }

    public BizException(Throwable cause) {
        super(cause);
    }

}
